import React, { Component } from 'react'
import { createForm } from 'rc-form';
import { Button, Input } from 'antd';
const nameRules = { required: true, message: "输入姓名" }
const passwordRules = { required: true, message: "输入密码" }
@createForm()
class HocPage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            userName: "",
            password: ""
        }
    }
    componentDidMount() {
        const { setFieldsValue } = this.props.form;
        setFieldsValue({ userName: "admin" })
    }

    handleSubmit = () => {
        //const { userName, password } = this.state;
        const { getFieldsValue } = this.props.form;
        console.log(getFieldsValue())
        //console.log(`name:${userName},password:${password}`)
    }

    handlename = (e) => {
        this.setState({ userName: e.target.value })
    }
    handlepasssword = (e) => {
        this.setState({ password: e.target.value })
    }
    render() {
        console.log('props:', this.props)
        const { getFieldDecorator } = this.props.form;
        return (
            <div>
                {getFieldDecorator('userName', { rules: [nameRules] })(
                    <Input type="text" placeholder="userName" />
                )}
                {
                    getFieldDecorator('password', { rules: [passwordRules] })(
                        <Input type="text" placeholder="password" />
                    )
                }
                <Button type="primary" onClick={this.handleSubmit}>提交</Button>
            </div>
        );
    }
}

export default HocPage;
